package com.qf.controller;

import com.qf.entity.Product;
import com.qf.enums.JxcEnum;
import com.qf.service.ProductService;
import com.qf.util.R;
import com.qf.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 作者: 王鑫
 * 项目名: jxc1
 * 时间:2019/12/4  20:42
 * 描述:
 */
@RestController
@RequestMapping("product")
public class ProductController {

    @Autowired
    private ProductService productService;

    @RequestMapping("list")
    public ResultVo list(){
        List<Product> list = productService.selectall();
        return R.ok(list);
    }


    @RequestMapping("quantity/{id}")
    public ResultVo quantity(@PathVariable("id") Integer id){
        int i = productService.selectCount(id);

        if (i == 0){
            return R.error(JxcEnum.CODE_ERROR);
        }else {
            return R.ok(i);
        }
    }

    /*

    查询商品库存
``
路径
GET		http://localhost/product/quantity/{id}
参数
	无
``
    响应数据
            成功
    {
        "code":0,
            "msg":"成功",
            "data":16
    }
    失败
    {
        "code":错误编码,
            "msg":"错误信息",
            "data":null
    }
*/




}
